﻿@page "/Bas/CodingList/Details"
@using nERP.ViewModel.Bas.CodingListVMs
@using nERP.Model.Bas
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <Display @bind-Value="@Model.Entity.Code" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.CurrentNumber" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.Example" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.CreateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.UpdateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.CreateBy" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.UpdateBy" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.IsValid" ShowLabel="true" />
        </Row>
        <Divider Icon="fa-fw fa-solid fa-bookmark" Text="@WtmBlazor.Localizer["Sys.ExtraInfo"]" Alignment="Alignment.Left" />

        <Table TItem="CodingRule"
               IsPagination="false"
               IsStriped="true" IsBordered="true" IsMultipleSelect="false" @bind-Items="@CodingRuleCodingListList2"
               ShowToolbar="false" ShowExtendButtons="false" ShowSkeleton="true">
            <TableColumns>
                <TableColumn @bind-Field="@context.Seq" Text="@WtmBlazor.Localizer["Page.序号"]" />
                <TableColumn @bind-Field="@context.CodeRule" Text="@WtmBlazor.Localizer["Page.规则"]" />
                <TableColumn @bind-Field="@context.FixedValue" Text="@WtmBlazor.Localizer["Page.固定值"]" />
                <TableColumn @bind-Field="@context.FixedRule" Text="@WtmBlazor.Localizer["Page.规则值"]" />
                <TableColumn @bind-Field="@context.GlideLen" Text="@WtmBlazor.Localizer["Page.流水号长度"]" />
                <TableColumn @bind-Field="@context.StartNumber" Text="@WtmBlazor.Localizer["Page.流水号起始值"]" />
                <TableColumn @bind-Field="@context.GlideStep" Text="@WtmBlazor.Localizer["Page.递增步长"]" />
                <TableColumn @bind-Field="@context.Glide" Text="@WtmBlazor.Localizer["Page.流水号补位码"]" />
                <TableColumn @bind-Field="@context.CreateTime" Text="@WtmBlazor.Localizer["_Admin.CreateTime"]" FormatString="yyyy-MM-dd HH:mm:ss" />
                <TableColumn @bind-Field="@context.UpdateTime" Text="@WtmBlazor.Localizer["_Admin.UpdateTime"]" FormatString="yyyy-MM-dd HH:mm:ss" />
                <TableColumn @bind-Field="@context.CreateBy" Text="@WtmBlazor.Localizer["_Admin.CreateBy"]" />
                <TableColumn @bind-Field="@context.UpdateBy" Text="@WtmBlazor.Localizer["_Admin.UpdateBy"]" />
                <TableColumn @bind-Field="@context.IsValid" Text="@WtmBlazor.Localizer["_Admin.IsValid"]" />
            </TableColumns>

        </Table>

        <div class="modal-footer table-modal-footer">
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private CodingListVM Model = new CodingListVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Bas/CodingList/Edit", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllCodingLists = new List<SelectedItem>();
    private IEnumerable<CodingRule> CodingRuleCodingListList2 { get; set; } = new List<CodingRule>();
    protected override async Task OnInitializedAsync()
    {


        AllCodingLists = await WtmBlazor.Api.CallItemsApi("/api/Bas/CodingRule/GetCodingLists");
        AllCodingLists.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<CodingListVM>($"/api/Bas/CodingList/{id}");
            Model = rv.Data;
        }
        CodingRuleCodingListList2 = Model.Entity.CodingRule_CodingList.OrderBy(x => x.Seq);

        await base.OnInitializedAsync();
    }
}
